package com.trade.module.base.repository;

import com.trade.module.base.entity.ResourceRole;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * Class Description: 資源角色數據持久層
 *
 * @Version v1.0 2017/4/22 21:06
 * @JDK version 1.8.0_51
 * @Author zfb
 */
public interface ResourceRoleRepository extends PagingAndSortingRepository<ResourceRole,String>,
        JpaSpecificationExecutor<ResourceRole>{
    /**
     * 根據角色id查詢資源角色集合
     *
     * @param roleId 角色id
     * @param roleDataFlag 角色刪除狀態
     * @param roleResDataFlag 角色資源刪除狀態
     * @return Iterable<ResourceRole> 資源角色集合
     */
    @Query("from ResourceRole rr WHERE rr.dataFlag=?3 AND rr.roleId IN " +
            "(SELECT r.id FROM Role r WHERE r.id=?1 AND r.dataFlag=?2) "+
            "order by rr.createTime ASC")
    Iterable<ResourceRole> findRoleResourceByRoleId(String roleId, String roleDataFlag, String roleResDataFlag);
}
